﻿using FastEventBus.Attribute;
using FastEventBus.Definition;
using FastEventBus.Entity;
using FastEventBus.Enum;
using FastEventBus.Exception;
using FastEventBus.Handle;
using FastUtil.Log;
using System;
using System.Collections.Generic;
using System.Text;

namespace FastEventBus.Application
{
    public class EventBus
    {
        private static EventBus EventBusIntance = null;
        private static object EventBus_Lock = new object();
        private static EventSession Session = null;

        public static EventBus GetInstance()
        {
            if (EventBusIntance == null)
            {
                lock (EventBus_Lock)
                {
                    if (EventBusIntance == null)
                    {
                        EventBusIntance = new EventBus();
                        Session = EventSessionFactory.OpenSession(EventHandlerStroageEnum.Redis);
                    }
                }
            }
            return EventBusIntance;
        }

        public void SetEventStroage(IFastEventStroage Stroge)
        {
            Session.Stroage = Stroge;
        }

        public void Subscribe(IFastEventHandler Handler)
        {
            Session.Subscribe(Handler);
        }

        public void Publish(string ChannelName, Dictionary<string, object> EventParamDic)
        {
            Session.Publish(ChannelName, EventParamDic);
        }
    }
}
